<style type="text/css">
a.get_wxtpl_button{ border:1px solid #ddd; border-radius:3px; padding:6px 8px; margin-left:10px; float:left;} 
</style> 
<table class="etable">  
	<tr>
		<td width="110">别名：</td>
		<td>
			<select name="alias">
			<{foreach item=i from=$notice_tag}>
				<option value="<{$i.id}>" <{if $row.nid == $i.id}>selected="selected"<{/if}>><{$i.name}></option>
			<{/foreach}>	
			</select>
		</td>
	</tr>
	<tr>
		<td>名称：</td>
		<td><input type="text" value="<{$row.name}>" size="50" id="name" name="name"></td>
	</tr>
	<{if $row.type == 'sms' || $row.type == 'wxtpl'}>
		<tr>
			<td>模板ID：</td>
			<td>
				<input type="text" value="<{$row.tpl_id}>" size="50" name="tpl_id" id="tpl_id">
				<{if $row.type == 'wxtpl'}>
					<a href="javascript:;" data-tpl="<{$row.type2}>" class="get_wxtpl_button" title="点击自动填写模板">获取</a>
				<{/if}>
			</td>
		</tr>
	<{/if}> 
	<tr>
		<td>传入参数：</td>
		<td><input type="text" value="<{$row.param}>" size="50" id="param" name="param"></td>
	</tr>
	<tr>
		<td>接口参数：</td>
		<td><input type="text" value="<{$row.param2}>" size="50" id="param2" name="param2"></td>
	</tr>
	<tr>
		<td>模板内容：</td>
		<td><textarea name="content" class="content" cols="50" rows="3" id="con"><{$row.content}></textarea></td>
	</tr> 
	<tr>
		<td>状态：</td>
		<td>
			<label><input type="radio" name="status" class="status" value="1" <{if $row.status == '1'}>checked="checked"<{/if}>/>开启</label>
			<label><input type="radio" name="status" class="status" value="0" <{if $row.status == '0'}>checked="checked"<{/if}>/>关闭</label>
		</td>
	</tr>
</table>  
<script type="text/javascript">
function ajax_submit(){ 
	<{if $row.type == 'sms' || $row.type == 'wxtpl'}>
		var tpl_id = $("#tpl_id").val(); 
	<{/if}>
	var name = $("#name").val(); 
	var con = $("#con").val();  
	var param = $("#param").val();  
	var param2 = $("#param2").val();  
	var status = $('input[name="status"]:checked').val();  
	$.ajax({
		type: 'POST',
		url: '?m=api&a=notice_tpl_save', 
		<{if $row.type == 'sms' || $row.type == 'wxtpl'}>
			data: {id:<{$row.id}>, name:name, tpl_id:tpl_id, param:param, param2:param2, content:con, status:status},
		<{else}>
			data: {id:<{$row.id}>, name:name, param:param, param2:param2, content:con, status:status},
		<{/if}> 
		success: function(result){
			data = jQuery.parseJSON(result); 
			if(data.error == '0'){
				parent.ajax_flush();
				parent.ajax_close();
			}else{
				alert(data.msg);
			} 
		}
	}); 
}
$.fn.extend({
	 insertAtCursor : function(myValue) {
		 var $t = $(this)[0];
		 if (document.selection) {
			 this.focus();
			 sel = document.selection.createRange();
			 sel.text = myValue;
			 this.focus();
		 } else if ($t.selectionStart || $t.selectionStart == '0') {
			 var startPos = $t.selectionStart;
			 var endPos = $t.selectionEnd;
			 var scrollTop = $t.scrollTop;
			 $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
			 this.focus();
			 $t.selectionStart = startPos + myValue.length;
			 $t.selectionEnd = startPos + myValue.length;
			 $t.scrollTop = scrollTop;
		 } else {
			 this.value += myValue;
			 this.focus();
		 }
	 }
});

$(function(){
    $(".tag a").click(function(){
		html = $(this).html();
        $(".content").insertAtCursor(html);
    });
	<{if $row.type == 'wxtpl'}> 
		$(document).unbind().on("click","a.get_wxtpl_button",function(){
			tpl_id = $(this).attr('data-tpl');
			$.ajax({
				type: 'POST',
				url: '?m=wchat&a=tpl_add',
				data: {tpl_id:tpl_id}, 
				success: function(result){
					var data = jQuery.parseJSON(result); 
					if(data.error == 0){
						$("#tpl_id").val(data.tpl_id);
					}else{
						alert(data.msg);
					}
				}
			}); 
		}); 
	<{/if}>
});  
</script>  